// 此方法ios可能不适配
function getdateTime(date) {
    var date = new Date(date); // date = '2022-5-02'||date = '2022-5'
    var new_year = date.getFullYear(); // 取当前的年份
    var month = date.getMonth();
    var new_month = month + 1; // 取当前的月份
    if (month > 12) {
        new_month -= 12; // 月份减
        new_year++; // 年份增
    }

    var firstDay = new Date(new_year + "-" + new_month + "-" + 1); // 取当年当月中的第一天
    var lastDay = new Date(new_year, new_month, 0).getDate(); // 获取当月最后一天日期
    if (firstDay.getMonth() + 1 < 10) {
        var mon = "0" + (firstDay.getMonth() + 1);
    } else {
        var mon = firstDay.getMonth() + 1;
    }
    var startDate =
        firstDay.getFullYear() + "-" + mon + "-" + "0" + firstDay.getDate();
    var endDate = firstDay.getFullYear() + "-" + mon + "-" + lastDay;
    var month_api = startDate + "," + endDate;
    console.log(month_api, "本月的起始时间");
}

/**
 * 获取指定月份(格式：yyyy-MM)第一天和最后一天，例如：2022-06,2022-06-01 2022-06-30
 */
function getRequireMonthStartAndEndDate(month) {
    let index = month.lastIndexOf('-')
    let nowYear = parseInt(month.substr(0, index)) // 当前年
    let nowMonth = parseInt(month.substr(index + 1)) - 1 // 当前月(值为0~11)
    let firstDate = new Date(nowYear, nowMonth, 1)
    let lastDate = new Date(nowYear, (nowMonth + 1), 0)
    let list = []
    list[0] = initDateFormat(firstDate)
    list[1] = initDateFormat(lastDate)
    console.log(nowYear, nowMonth, firstDate, lastDate, list[0], list[1])
    return list
}
function initDateFormat(date) {
    let month = date.getMonth() + 1 < 10 ? '0' + parseInt(date.getMonth() + 1) : date.getMonth() + 1
    let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    return date.getFullYear() + '-' + month + '-' + day
}